//
//  LYQLoginChooseViewController.m
//  ZCProject
//
//  Created by Zheng on 16/11/15.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQLoginChooseViewController.h"
#import "LYQPhoneLoginViewController.h"
#import "LYQMainTabBarController.h"
#import "LYQLoginSettingPasswordViewController.h"

@interface LYQLoginChooseViewController ()

@property (nonatomic, strong) UIImageView *bgImgv; //背景
@property (nonatomic, strong) UIButton *loginBtn; //登录
@property (nonatomic, strong) UIButton *registerBtn; //注册
@property (nonatomic, strong) UIButton *lookBtn; //随便看看

@end

@implementation LYQLoginChooseViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.bgImgv];
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    UIBarButtonItem *backbutton = [[UIBarButtonItem alloc] init];
    [backbutton setTitleTextAttributes:@{NSFontAttributeName:kWFont(15)} forState:UIControlStateNormal];
    backbutton.title = @"返回";
    self.navigationItem.backBarButtonItem = backbutton;
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    
    self.navigationController.navigationBarHidden = YES;
    
    [self layoutSubviewsInView];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    self.navigationController.navigationBarHidden = NO;
    
}


#pragma mark - layoust subviews
- (void)layoutSubviewsInView {
    
    [_bgImgv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self.view);
    }];
    
    [_lookBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@(-kWScale(55)));
        make.centerX.equalTo(_bgImgv);
    }];
    
    [_registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_lookBtn.mas_top).offset(-kWScale(25));
        make.left.equalTo(_bgImgv).offset(kWScale(45));
        make.right.equalTo(_bgImgv).offset(-kWScale(45));
        make.height.equalTo(@(kWScale(37)));
    }];
    
    [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_registerBtn.mas_top).offset(-kWScale(15));
        make.left.right.equalTo(_registerBtn);
        make.height.equalTo(@(kWScale(40)));
    }];
}


#pragma mark - load sbuviews
- (UIImageView *)bgImgv {
    if (!_bgImgv) {
        _bgImgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_bg"]];
        _bgImgv.userInteractionEnabled = YES;
        
        [_bgImgv addSubview:self.lookBtn];
        [_bgImgv addSubview:self.registerBtn];
        [_bgImgv addSubview:self.loginBtn];
    }
    return _bgImgv;
}

- (UIButton *)lookBtn {
    if (!_lookBtn) {
        _lookBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_lookBtn setTitle:@"随便看看" forState:UIControlStateNormal];
        [_lookBtn setTitleColor:kLYQBlue forState:UIControlStateNormal];
        _lookBtn.titleLabel.font = kWFont(14);
        [_lookBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _lookBtn;
}

- (UIButton *)registerBtn {
    if (!_registerBtn) {
        _registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _registerBtn.backgroundColor = [UIColor whiteColor];
        [_registerBtn setTitle:@"注册" forState:UIControlStateNormal];
        [_registerBtn setTitleColor:kLYQBlue forState:UIControlStateNormal];
        _registerBtn.titleLabel.font = kWFont(16);
        _registerBtn.layer.cornerRadius = kWScale(18.5);
        _registerBtn.layer.borderColor = [kLYQBlue CGColor];
        _registerBtn.layer.borderWidth = kWScale(1.5);
        [_registerBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _registerBtn;
}

- (UIButton *)loginBtn {
    if (!_loginBtn) {
        _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _loginBtn.backgroundColor = kLYQBlue;
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        [_loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _loginBtn.titleLabel.font = kWFont(16);
        _loginBtn.layer.cornerRadius = kWScale(20);
        [_loginBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _loginBtn;
}

#pragma mark - button action
- (void)btnAction:(UIButton *)sender {
    if ([sender.titleLabel.text isEqualToString:@"随便看看"]) {
        //随便看看
        LYQMainTabBarController *lyqMainCtrl = [[LYQMainTabBarController alloc] init];
        [UIApplication sharedApplication].keyWindow.rootViewController = lyqMainCtrl;
    } else if ([sender.titleLabel.text isEqualToString:@"注册"]) {
        //注册
        LYQLoginSettingPasswordViewController *lspVC = [[LYQLoginSettingPasswordViewController alloc] init];
        lspVC.navigationItem.title = @"手机注册";
        [self.navigationController pushViewController:lspVC animated:YES];
    } else {
        //登录
        LYQPhoneLoginViewController *plVC = [[LYQPhoneLoginViewController alloc] init];
        [self.navigationController pushViewController:plVC animated:YES];
    }
}


#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
